package com.jz.pay.consumer.topicListener;

import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RetryListener implements MessageListenerConcurrently {
    public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext queue){
        MessageQueue messageQueue = queue.getMessageQueue();
        System.out.println("----------------------------------------------------------");
        System.out.println("本次接收："+messageQueue.getBrokerName()+" "+messageQueue.getTopic()+" "+msgs.size());
        for (int i = 0; i < msgs.size(); i++) {
            MessageExt msg = msgs.get(i);
            String body = new String(msg.getBody());
            System.out.println(messageQueue.getBrokerName()+","+messageQueue.getTopic()+"   "+ body+" "+msg.getMsgId());
        }
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    }
}
